using System;
using System.Collections;
using System.Data;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class CarCoverTypeDB
    {
        public CarCoverTypeDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(CarCoverType covertype)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarCoverTypeInsertUpdateSingleItem]";
            
            SortedList _sPara = new SortedList();
            
            #region Parameter
            _sPara.Add("@ProviderCarCoverTypeId", covertype.ProviderCoverTypeId);
            _sPara.Add("@ProviderCompanyId", covertype.ProviderCompanyId);
            _sPara.Add("@CXCoverTypeId", covertype.CXCoverTypeId);
            _sPara.Add("@PackageId", covertype.PackageId);
            _sPara.Add("@ProviderCoverTypeDesc", covertype.ProviderCoverTypeDescription);
            _sPara.Add("@CoverRate", covertype.CoverRate);
            _sPara.Add("@MinPremiumAmount", covertype.MinPremiumAmount);
            _sPara.Add("@MaxPremiumAmount", covertype.MaxPremiumAmount);
            _sPara.Add("@RefCEUserId", covertype.RefCEUserId);
            _sPara.Add("@Status", covertype.Status);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public bool Delete(Int64 CXCoverTypeId, Int64 ProviderCompanyId, Int64 PackageId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderCarCoverTypeDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CXCoverTypeId", CXCoverTypeId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            _sPara.Add("@PackageId", PackageId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }

        public bool Update()
        {
            return true;
        }

        public CarCoverTypeList GetProviderCoverTypeList(Int64 ProviderCompanyId)
        {
            CarCoverTypeList _covertypelist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCoverTypeSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _covertypelist = new CarCoverTypeList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        CarCoverType _covertype = new CarCoverType();
                        _covertype = FillDataRecord(_dt, i);
                        _covertypelist.Add(_covertype);
                    }
                }
            }
            return _covertypelist;
        }


        public CarCoverType GetProviderCoverType(Int64 ProviderCompanyId, Int32 CXCoverTypeId,Int64 PackageId)
        {
            CarCoverType _covertype = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderCarCoverTypeSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);
            _spara.Add("@CXCoverTypeId", CXCoverTypeId);
            _spara.Add("@PackageId", PackageId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _covertype = new CarCoverType();
                    _covertype = FillDataRecord(_dt, 0);
                }
            }
            return _covertype;
        }

        public CarCoverType GetProviderCoverType(Int64 ProviderCoverTypeId)
        {
            CarCoverType _covertype = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderWorkShopSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@WorkShopId", ProviderCoverTypeId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _covertype = new CarCoverType();
                    _covertype = FillDataRecord(_dt, 0);
                }
            }
            return _covertype;
        }

        private CarCoverType FillDataRecord(DataTable myDataTable, int RowId)
        {
            CarCoverType myCoverType = new CarCoverType();
            myCoverType.ProviderCoverTypeId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCarCoverTypeId"].ToString());
            myCoverType.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myCoverType.ProviderCoverTypeDescription = myDataTable.Rows[RowId]["ProviderCoverTypeDesc"].ToString();
            myCoverType.CXCoverTypeId = Convert.ToInt32(myDataTable.Rows[RowId]["CXCoverTypeId"].ToString());
            myCoverType.PackageId = Convert.ToInt32(myDataTable.Rows[RowId]["PackageId"].ToString());
            myCoverType.CoverRate = Convert.ToSingle(myDataTable.Rows[RowId]["CoverRate"].ToString());
            myCoverType.MinPremiumAmount = Convert.ToSingle(myDataTable.Rows[RowId]["MinPremiumAmount"].ToString());
            myCoverType.MaxPremiumAmount = Convert.ToSingle(myDataTable.Rows[RowId]["MaxPremiumAmount"].ToString());
            myCoverType.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myCoverType.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            return myCoverType;
        }
        
    }
}